﻿using Demo.Net.EFCore;
using Demo.Net.EFCore.Entity;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mapster;

namespace Demo.Net.Service.Service
{
    public class EFCoreService
    {

        private readonly EFCoreDBContext _dbCon;

        public EFCoreService( EFCoreDBContext dbCon)
        {

            _dbCon = dbCon;
        }


        /// <summary>
        /// 简单测试 获取全部用户
        /// </summary>
        /// <returns></returns>
        public async Task<List<tusr_user>> GetTest()
        {
            var userList = await _dbCon.tusr_user.AsQueryable().AsNoTracking().ToListAsync();
            return userList;
        }


        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task Update(tusr_user user)
        {
            var upd = await _dbCon.tusr_user.FirstOrDefaultAsync(p => p.user_id == user.user_id);
            if (upd != null) 
            {
                _dbCon.tusr_user.Update(user.Adapt(upd));
                await _dbCon.SaveChangesAsync();
            }
     
         
            
        }

    }
}
